package vcp.client.reports;

import java.io.Serializable;

import org.joda.time.format.DateTimeFormat;

import vcp.entity.Customer;
import vcp.entity.Subscription;
import vcp.entity.SubscriptionHistory;
import vcp.enums.ReportType;
/**
 * 
 * @author VCP team
 *<p> subscription report class </p>
 */
public class SubscriptionsReport extends ReportAbstract
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 2485993209245868672L;

	/**
	 * Subscription report constructor
	 */
	public SubscriptionsReport ()
	{
		super(ReportType.SUBSCRIPTION);
	}

	// ****************************************************************************************************************************
	// Public methods
	// ****************************************************************************************************************************
	/**
	 * adds customer in subscription
	 * @param subscription
	 * @param customer
	 */
	public void add ( Subscription subscription, Customer customer )
	{
		SubscriptionRowWrapper dataWrapper = new SubscriptionRowWrapper();

		dataWrapper.setSubscriptionID(subscription.getSubscribtionID());
		dataWrapper.setCustomerName(customer.getUserFirstName() + " " + customer.getUserLastName());
		dataWrapper.setSiteName(subscription.getSite() != null
				? subscription.getSite().toString()
						: "All");
		dataWrapper.setSubscriptionType(subscription.getSubscriptionType().toString());
		dataWrapper.setStartDate(DateTimeFormat.forPattern("dd/MM/yyyy").print(subscription.getStartDate()));
		dataWrapper.setEndDate(DateTimeFormat.forPattern("dd/MM/yyyy").print(subscription.getEndDate()));

		this.reportDataRow.add(dataWrapper);
	}
	/**
	 * adds customer to subscription history
	 * @param subscriptionHistory
	 * @param customer
	 */
	public void add ( SubscriptionHistory subscriptionHistory, Customer customer )
	{
		SubscriptionRowWrapper dataWrapper = new SubscriptionRowWrapper();

		dataWrapper.setSubscriptionID(subscriptionHistory.getSubscriptionID());
		dataWrapper.setCustomerName(customer.getUserFirstName() + " " + customer.getUserLastName());
		dataWrapper.setSiteName(subscriptionHistory.getSite() != null
				? subscriptionHistory.getSite().toString()
						: "All");
		dataWrapper.setSubscriptionType(subscriptionHistory.getSubscriptionType().toString());
		dataWrapper.setStartDate(DateTimeFormat.forPattern("dd/MM/yyyy").print(subscriptionHistory.getStartDate()));
		dataWrapper.setEndDate(DateTimeFormat.forPattern("dd/MM/yyyy").print(subscriptionHistory.getEndDate()));

		this.reportDataRow.add(dataWrapper);
	}

	// ****************************************************************************************************************************
	// ReportAbstract methods
	// ****************************************************************************************************************************
	@Override
	public String[] getHeaders ()
	{
		return new String[]
				{ "Subscription ID",
				"Customer",
				"Site Name",
				"Subscribtions Type",
				"Start Date",
				"End Date" };
	}

	// ****************************************************************************************************************************
	// Private class
	// ****************************************************************************************************************************
	/**
	 * 
	 * @author VCP team
	 *<p> subscription row wrapper class
	 */
	private class SubscriptionRowWrapper implements Serializable, IWrapperConverter
	{
		/**
		 * 
		 */
		private static final long serialVersionUID = - 761492630516383825L;

		// ****************************************************************************************************************************
		// Setter-Getter methods
		// ****************************************************************************************************************************
		private String siteName;
		/**
		 * getter
		 * @return site name
		 */
		public String getSiteName ()
		{
			return this.siteName;
		}
		/**
		 * setter
		 * @param siteName
		 */
		public void setSiteName ( String siteName )
		{
			this.siteName = siteName;
		}

		private String endDate;
		/**
		 * getter
		 * @return end date
		 */
		public String getEndDate ()
		{
			return this.endDate;
		}
		/**
		 * setter
		 * @param endDate
		 */
		public void setEndDate ( String endDate )
		{
			this.endDate = endDate;
		}

		private String startDate;
		/**
		 * getter
		 * @return start date
		 */
		public String getStartDate ()
		{
			return this.startDate;
		}
		/**
		 * setter
		 * @param startDate
		 */
		public void setStartDate ( String startDate )
		{
			this.startDate = startDate;
		}

		private String subscriptionType;
		/**
		 * getter
		 * @return subscription type
		 */
		public String getSubscriptionType ()
		{
			return this.subscriptionType;
		}
		/**
		 * setter
		 * @param subscriptionType
		 */
		public void setSubscriptionType ( String subscriptionType )
		{
			this.subscriptionType = subscriptionType;
		}

		private String customerName;
		/**
		 * getter
		 * @return customer name
		 */
		public String getCustomerName ()
		{
			return this.customerName;
		}
		/**
		 * setter
		 * @param customerName
		 */
		public void setCustomerName ( String customerName )
		{
			this.customerName = customerName;
		}

		private Integer subscriptionID;
		/**
		 * getter
		 * @return subscription id
		 */
		public Integer getSubscriptionID ()
		{
			return this.subscriptionID;
		}
		/**
		 * setter
		 * @param subscriptionID
		 */
		public void setSubscriptionID ( Integer subscriptionID )
		{
			this.subscriptionID = subscriptionID;
		}

		// ****************************************************************************************************************************
		// IWrapperConverter methods
		// ****************************************************************************************************************************
		/**
		 * @return Wrapped row as Object[]
		 */
		@Override
		public Object[] toObjectArray ()
		{
			return new Object[]
					{ this.getSubscriptionID()
					, this.getCustomerName()
					, this.getSiteName()
					, this.getSubscriptionType()
					, this.getStartDate()
					, this.getEndDate() };
		}
	}
}
